package baza_mysql;

//import com.mysql.jdbc.Connection;

//import com.mysql.jdbc.Statement;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import oo.rejestracja;

import sesja.sesjaimpl;

class Connect_Database extends sesjaimpl{

	private String 
		str_database,str_user,str_password;
	
	/**
	 * @return the str_database
	 */
	protected String getStr_database() {
		return str_database;
	}

	/**
	 * @param str_database the str_database to set
	 */
	protected void setStr_database(String str_database) {
		this.str_database = str_database;
	}

	/**
	 * @return the str_user
	 */
	protected String getStr_user() {
		return str_user;
	}

	/**
	 * @param str_user the str_user to set
	 */
	protected void setStr_user(String str_user) {
		this.str_user = str_user;
	}

	/**
	 * @return the str_password
	 */
	protected String getStr_password() {
		return str_password;
	}

	/**
	 * @param str_password the str_password to set
	 */
	protected void setStr_password(String str_password) {
		this.str_password = str_password;
	}
	protected Connection con=null;
	
	/**
	 * 
	 * @param database_number 1(mysql),2(oracle)
	 * @param database nazwa bazy
	 * @param user wiadomo
	 * @param pass wiadomo
	 * @param polaczenie 1(lokalne),2(eatj)
	 */
	public Connect_Database(int database_number,String database,String user,String pass,int polaczenie){
		this.str_database=database;
		this.str_user=user;
		this.str_password=pass;
		
		switch(database_number)
		{
		case 1:
			mysql(polaczenie);
			break;
		/*case 2:
			oracle_(polaczenie);
			break;*/
		}
	}
	
	private Connect_Database() {
		super();
	}

	/**
	 * tylko polaczenie z baza oracle
	 */
	private void oracle(int polaczenie){
		try{
			  Class.forName("com.mysql.jdbc.Driver");
		}
		catch(Exception e){
			System.out.println("blad konstruktor1"+e.getMessage());
		}
		try{
			  /*switch(polaczenie)
			  {
			  case 1:
				  //lokalnie
				  con =  (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/"+str_database,str_user,str_password);
				  break;
			  case 2:
			      //na eatj
			      con =  (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3307/matmon?autoReconnect=true");
			      break;
			  case 3:*/
				  //na eatj mysql4
				  //con =  (Connection) DriverManager.getConnection("jdbc:mysql://localhost/matmon?autoReconnect=true", "matmon", "mateus80hyski");
				  con = DriverManager.getConnection("jdbc:mysql://localhost/matmon?autoReconnect=true", "matmon","mateusz80hyski"); 
				  //break;
			  //}
			}
			catch(Exception e1){
				System.out.println("blad konstruktor"+e1.getMessage());
			}
	}
	/**
	 * tylko polaczenie z baza mysql
	 */
	private void mysql(int polaczenie){
		try{
			  Class.forName("com.mysql.jdbc.Driver");
		}
		catch(Exception e){
			System.out.println("blad konstruktor1"+e.getMessage());
		}
		try{
			  /*switch(polaczenie)
			  {
			  case 1:
				  //lokalnie
				  con =  (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/"+str_database,str_user,str_password);
				  break;
			  case 2:
			      //na eatj
			      con =  (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3307/matmon?autoReconnect=true");
			      break;
			  case 3:*/
				  //na eatj mysql4
				  //con =  (Connection) DriverManager.getConnection("jdbc:mysql://localhost/matmon?autoReconnect=true", "matmon", "mateus80hyski");
				  con = DriverManager.getConnection("jdbc:mysql://localhost/matmon?autoReconnect=true", "matmon","mateusz80hyski"); 
				  //break;
			  //}
			}
			catch(Exception e1){
				System.out.println("blad konstruktor"+e1.getMessage());
			}
	}
	public Connection getCon() {
		return con;
	}

	public void setCon(Connection con) {
		this.con = con;
	}
	
}
